package com.dp.factory.factory_method.controller;

import com.dp.factory.factory_method.factory.FreeGoodsFactoryMap;
import com.dp.factory.factory_method.factory.impl.DiscountFreeGoodsFactory;
import com.dp.factory.factory_method.factory.FreeGoodsFactory;
import com.dp.factory.factory_method.factory.impl.SmallGiftFreeGoodsFactory;
import com.dp.factory.simple_factory.entity.AwardInfo;
import com.dp.factory.simple_factory.entity.ResponseResult;
import com.dp.factory.simple_factory.service.IFreeGoods;


/**
 * @Author: Ruomeng
 * @Date: 2024/11/26
 * @Description : design-pattern
 * @Version: 1.0
 */
public class DeliverController {
    public ResponseResult awardToUser(AwardInfo awardInfo) {
        // 根据类型获取具体工厂
        FreeGoodsFactory goodsFactory = FreeGoodsFactoryMap.getParserFactory(awardInfo.getAwardTypes());
        // 根据工厂获取实例
        IFreeGoods iFreeGoods = goodsFactory.getInstance();

        System.out.println("---------工厂方法模式---------");
        return iFreeGoods.sendFreeGoods(awardInfo);
    }
}
